package cn.edu.sgu.www.mhxysy.controller.chongwu;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.chongwu.ChongwuAttributeDTO;
import cn.edu.sgu.www.mhxysy.entity.chongwu.ChongwuAttribute;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.chongwu.ChongwuAttributeService;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "宠物属性管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/chongwu_attribute", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class ChongwuAttributeController {

	private final ChongwuAttributeService chongwuAttributeService;

	@Autowired
	public ChongwuAttributeController(ChongwuAttributeService chongwuAttributeService) {
		this.chongwuAttributeService = chongwuAttributeService;
	}

	@ApiOperation("通过ID修改宠物属性")
	@RequestMapping(value = "/updateById", method = RequestMethod.POST)
	public JsonResult<Void> updateById(@Validated ChongwuAttributeDTO chongwuAttributeDTO) {
		chongwuAttributeService.updateById(chongwuAttributeDTO);

		return JsonResult.success(CustomMessages.UPDATE_SUCCESS);
	}

	@ApiOperation("通过ID查询宠物属性")
	@RequestMapping(value = "/selectById", method = RequestMethod.GET)
	public JsonResult<ChongwuAttribute> selectById(
			@ApiParam(name = "id", value = "宠物属性ID", required = true)
			@NotBlank(message = CustomMessages.ID_NOT_NULL) String id) {
		ChongwuAttribute chongwuAttribute = chongwuAttributeService.selectById(id);

		return JsonResult.success(null, chongwuAttribute);
	}

	@ApiOperation("通过宠物ID查询宠物属性")
	@RequestMapping(value = "/selectByChongwuId", method = RequestMethod.GET)
	public JsonResult<ChongwuAttribute> selectByChongwuId(
			@ApiParam(name = "chongwuId", value = "宠物ID", required = true)
			@NotBlank(message = CustomMessages.CHONGWU_ID_NOT_NULL) String chongwuId) {
		ChongwuAttribute chongwuAttribute = chongwuAttributeService.selectByChongwuId(chongwuId);

		return JsonResult.success(null, chongwuAttribute);
	}

}